#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

/*
模拟题：
反思，一定要在草稿纸上演算清楚再动手写代码，不然就wa
*/
using namespace std;
using LL = long long;

int n, m;
string op;

bool check(int l, int r, int d, int u){
    int k1 = r - l + 1;
    int k2 = d - u + 1;

    if(k1 <= m && k2 <= n) return true;
    return false;
}

void solve(){
    cin >> n >> m >> op;
    
    int sx = 0, sy = 0;
    int l = 0, r = 0, d = 0, u = 0;
    for(int i = 0; i < op.length(); i ++){
        if(op[i] == 'L'){
            sy --;
            int tl = min(l, sy);
            // cout << tl << '\n';
            if(check(tl, r, d, u)){
                l = tl;
            } else{
                 cout << 1 + abs(u) << " " << 1 + abs(l) << '\n';
                return;
            }
        }else if(op[i] == 'R'){
            sy ++;
            int tr = max(r, sy);

            if(tr > 0)
            if(check(l, tr, d, u)){
                r = tr;
            } else{
                 cout << 1 + abs(u) << " " << 1 + abs(l) << '\n';
                return; 
            }
        }else if(op[i] == 'U'){
            sx --;
            int tu = min(u, sx);
            if(check(l, r, d, tu)){
                u = tu;
            } else{
                cout << 1 + abs(u) << " " << 1 + abs(l) << '\n';
                return; 
            }
        }else{ // D
            sx ++;
            int td = max(d, sx);
            if(check(l, r, td, u)){
                d = td;
            } else{
                cout << 1 + abs(u) << " " << 1 + abs(l) << '\n';
                return; 
            }
        }

        // if(abs(l) == 2 && i + 1 == 10) cout << l << " " << r << " " << d << " " << u << "\n";
    }

    cout << 1 + abs(u) << " " << 1 + abs(l) << '\n';
                
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    int T;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}